package com.chatplus.application.domain.response;

import cn.hutool.core.util.PhoneUtil;
import com.chatplus.application.common.domain.model.UserAccount;
import com.chatplus.application.json.Int64AsString;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.io.Serializable;

/**
 * 当前登录商家信息
 */
public class MerchantInfoResponse implements Serializable {
    private static final long serialVersionUID = 4752735228545678594L;
    /**
     * 账号Id
     */
    @JsonSerialize(using = Int64AsString.class)
    private Long id;
    /**
     * 登录手机号码
     */
    private String phone;
    /**
     * 昵称;对应[accountNumber.nickname]
     */
    private String nickName;
    /**
     * 联系电话
     */
    private String contactPhone;
    /**
     * 头像图片地址
     */
    private String avatarUrl;

    public static MerchantInfoResponse fromUserAccount(UserAccount userAccount) {
        MerchantInfoResponse merchantInfoResponse = new MerchantInfoResponse();
        merchantInfoResponse.setId(userAccount.getId());
        String phone = userAccount.getPhone().substring(0,3) + "****" + userAccount.getPhone().substring(7);
        merchantInfoResponse.setPhone(phone);
        merchantInfoResponse.setNickName(userAccount.getNickName());
        if (PhoneUtil.isMobile(userAccount.getContactPhone())) {
            String contactPhone = userAccount.getContactPhone().substring(0,3) + "****" + userAccount.getContactPhone().substring(7);
            merchantInfoResponse.setContactPhone(contactPhone);
        }
        merchantInfoResponse.setAvatarUrl(userAccount.getAvatarUrl());
        return merchantInfoResponse;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getContactPhone() {
        return contactPhone;
    }

    public void setContactPhone(String contactPhone) {
        this.contactPhone = contactPhone;
    }

    public String getAvatarUrl() {
        return avatarUrl;
    }

    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }
}
